﻿@using CoralNode.Core.Entity.Domains.Node
@using CoralNode.Core.Entity.Domains.Prototype
@using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Helper
@using Coralcode.Adapter.StatVisit.Entity.Domains
@model NodeDomain
@{
    Layout = null;
    bool isSeo = false;
}
<script src="/Themes/CoralAdmin/_misc/scripts/ueditor/ueditor.all.js"> </script>
<script src="/Themes/CoralAdmin/_misc/scripts/ueditor/ueditor.config.js"> </script>
<div>
    <div class="scrolltab-triggers extra_normal">
        <a href="javascript:">主要信息</a>
        @foreach (PrototypeFieldGroupDomain group in @ViewBag.FieldGroupList) {
            if (group.FieldList.Count(n => n.FieldType == NodeEnums.FunctionFieldType.Seo) > 0) {
                isSeo = true;
            }
            <a href="javascript:">@group.Title</a>
        }
        @if (isSeo) {
            <a href="javascript:">SEO设置</a>
        }
    </div>
    <form id="spform" action="/m/node/editNode/@Model.Id?categoryId=@Model.CategoryId&prototypeId=@Model.PrototypeId" method="post" enctype="multipart/form-data">
        @if (@ViewBag.Msg != null) {
            <div class="error_msg">
                @ViewBag.Msg.Msg
            </div>
        }
        <div class="pt_1 scrolltab-items">
            <div class="table_form form_main ">
                <div class="scrolltab-item-t">
                    <span class="btn"></span>主要信息
                </div>
                <div class="pl_2">
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)
                    <table>
                        <tbody>
                            <tr>
                                <th width="60"><span class="signmark">*</span>标题：</th>
                                <td>
                                    @Html.TextBoxFor(m => m.Title, new { @class = "text w_37 required" })
                                </td>
                            </tr>
                            <tr>
                                <th>所属分类：</th>
                                <td>
                                    <div class="ztreeContainer">
                                        <input type="text" class="text js_ztree_trigger" style="width: 120px;" value="@Model.Category.Title" id="category_title"  />
                                        <input type="hidden" name="CategoryId" id="category_id" value="@Model.CategoryId"  />
                                        <span><a id="menuBtn" href="#" class="js_ztree_trigger">选择</a></span>
                                        <ul id="categoryTree" class="ztree" style="margin-top: 0; width: 180px;"></ul>
                                        <textarea class="js_ztree_data">@ViewBag.CategoryList</textarea>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th>排序：</th>
                                <td>@Html.TextBoxFor(m => m.Rank, new { @class = "text w_37" })
                                </td>
                            </tr>
                            <tr>
                                <th>发布时间：</th>
                                <td>
                                    <input type="text" class="text w_13 datepicker" name="CreateTime" value="@Model.CreateTime.ToString("yyyy-MM-dd HH:mm")"/>
                                </td>
                            </tr>
                            <tr>
                                <th>内容状态：</th>
                                <td>
                                    @foreach (var item in @ViewBag.NodeStatusList) {
                                        if (Model.Status == @item.Value) {
                                        <label class="mr_2">
                                            <input name="Status"  class="radio" checked="checked" type="radio" value="@item.Value"><span>@item.Key</span></label>
                                        } else {
                                        <label class="mr_2">
                                            <input name="Status" class="radio" type="radio" value="@item.Value"><span>@item.Key</span></label>
                                        }
                                    }
                                </td>
                            </tr>
                            @if (@Model.ProcessList.Count > 0) {
                                foreach (var pro in Model.ProcessList) {
                                <tr>
                                    <th style="width: 80px;">
                                        <label>@pro.Title：</label>
                                    </th>
                                    <td>
                                        <div class="slt js-select" name="process.@(pro.Code)" wd="264" swd="220">
                                            <div class="curr"><span></span></div>
                                            <div class="show">
                                                <ul>
                                                    @foreach (var item in @pro.EntryList) {
                                                        string fieldValue = pro.FieldValue != null ? pro.FieldValue.FaceValue : pro.DefaultValue;
                                                        if (item.EntryValue == fieldValue) {
                                                        <li selected="selected"  val="@item.EntryValue"><a>@item.EntryName</a></li>
                                                        } else {
                                                        <li  val="@item.EntryValue"><a>@item.EntryName</a></li>
                                                        }
                                                    }
                                                </ul>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                }
                            }
                        </tbody>
                    </table>
                </div>
            </div>
            @foreach (var group in @Model.FieldGroupList) {
@*<div class="switch_tab">
                            <span class="btn"><i class="ico ico_slideswitch_show"></i></span>@group.Title
                        </div>*@
                <div class="table_form form_main">
                    <div class="scrolltab-item-t">
                        <span class="btn"></span>@group.Title
                    </div>
                    <div class="pl_2">
                        <table>
                            <tbody>
                                @if (group.FieldList.Count(n => n.FieldType == NodeEnums.FunctionFieldType.Seo) > 0) {
                                    isSeo = true;
                                }
                                @foreach (var item in @group.FieldList.Where(n => n.FieldType != NodeEnums.FunctionFieldType.Seo)) {
                                    string fieldValue = item.FieldValue != null ? item.FieldValue.FaceValue : item.DefaultValue;
                                    <tr>
                                        <th width="80px">@item.Title：</th>
                                        <td>
                                            @if (@item.FieldType == NodeEnums.BasicFieldType.TextField) {
                                                if (string.IsNullOrEmpty(@item.Measurement)) {
                                                <input class="text w_37" type="text" name="field.@item.FieldName" validate="@item.Validator" value="@fieldValue" />
                                                } else {
                                                <input class="text @item.Measurement w_15" type="text" name="field.@item.FieldName" validate="@item.Validator" value="@fieldValue" />@*
                                                        <span class="l ml_2">@item.Measurement</span>*@
                                                }
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.TextArea) {
                                                <textarea name="field.@item.FieldName" validate="@item.Validator" class="h_8 w_37">@fieldValue</textarea>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.PasswordField) {
                                                <input name="field.@item.FieldName" class="text w_37" validate="@item.Validator" type="password" value="@fieldValue"/>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.RadioButton) {
                                                foreach (var e in @item.EntryList) {
                                                    if (@e.EntryValue == @fieldValue) {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" validate="@item.Validator" class="radio" checked="checked" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                <div class="exp ml_1">@item.Hint</div>
                                                    } else {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" class="radio" validate="@item.Validator" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                <div class="exp ml_1">@item.Hint</div>
                                                    }
                                                }
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.CheckBox) {
                                                foreach (var e in @item.EntryList) {
                                                    if (@ManageHtmlHelper.Contains(@fieldValue, @e.EntryValue)) {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" validate="@item.Validator" class="checkbox"  checked="checked" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                <div class="exp ml_1">@item.Hint</div>
                                                    } else {
                                                <label class="mr_2">
                                                    <input name="field.@item.FieldName" validate="@item.Validator" class="checkbox" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                <div class="exp ml_1">@item.Hint</div>
                                                    }
                                                }

                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.SelectBox) {
                                                <select validate="@item.Validator" name="field.@item.FieldName" style="width:382px">
                                                    @foreach (var e in @item.EntryList) {
                                                        if (@e.EntryValue == @fieldValue) {
                                                        <option value="@e.EntryValue" selected="selected">@e.EntryName</option>
                                                        } else {
                                                        <option value="@e.EntryValue">@e.EntryName</option>
                                                        }
                                                    }

                                                </select>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.FileField) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@fieldValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:false,method:'add',type:'file'}">
                                                        <span class="ico ico_upload_file"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiFile) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@fieldValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:true,method:'add',type:'file'}">
                                                        <span class="ico ico_upload_file"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.ImageField) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@fieldValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:false,method:'add',type:'image'}">
                                                        <span class="ico ico_upload_image"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiImage) {
                                                <input type="hidden" validate="@item.Validator" name="field.@item.FieldName" value="@fieldValue"/>
                                                <ul class="list_img" href="/m/common/upload" data-js="listimg">
                                                    <li class="btn li_add js_openuploader" data-meta="{data:'{module:\'@Model.Prototype.Code/@item.FieldName\'}',multi:true,method:'add',type:'image'}">
                                                        <span class="ico ico_upload_image"></span>
                                                    </li>
                                                </ul>
                                                <div class="exp ml_1">@item.Hint</div>
                                            } else if (item.FieldType == NodeEnums.BasicFieldType.SingleData) {
                                                IList<NodeDomain> relationList = ViewBag.RelationNodeList;
                                                relationList = relationList.Where(n => n.PrototypeId == long.Parse(item.DefaultValue)).ToList();
                                                IList<NodeDomain> nodeRelationList = ViewBag.RelationNode;
                                                var relateNode = nodeRelationList.FirstOrDefault(n => n.PrototypeId == long.Parse(item.DefaultValue));
                                                var length = item.Measurement == "1" ? relateNode != null ? 1 : 0 : relationList.Count;
                                                var singleValue = item.Measurement == "1" ? relateNode != null ? relateNode.Id.ToString() : string.Empty : string.Join(",", relationList.Select(n => n.Id));
                                                <a class="j_addRelation" num="@item.Measurement" val="@singleValue" href="/m/node/singlerelation?PrototypeId=@item.DefaultValue">
                                                    已选择@(length)条数据</a>
                                                if (item.Measurement == "1") {
                                                <input type="hidden" name="field.@item.FieldName" value="@singleValue"/>
                                                } else {
                                                <input type="hidden" name="field.@item.FieldName" value="@singleValue"/>
                                                }
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.StatVisitInitial) {
                                                StatVisitInitialDomain st = ViewBag.VisitInitial ?? new StatVisitInitialDomain();
                                                <ul>
                                                    <li>
                                                        <label>初始PV数</label><input class="text w_37" type="text" name="VisitStat.PageView" value="@st.PageView" />
                                                    </li>
                                                    <li>
                                                        <label>初始UV数</label><input class="text w_37" type="text" name="VisitStat.UniqueVisitor" value="@st.UniqueVisitor" />
                                                    </li>
                                                    <li>
                                                        <label>初始IP数</label><input class="text w_37" type="text" name="VisitStat.IpCount" value="@st.IpCount" />
                                                    </li>
                                                </ul>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Tag) {

                                                IList<PrototypeTagDomain> tagList = ViewBag.NodeTagList;
                                                string tagArray = string.Join(",", (from t in tagList select t.Title).ToArray());
                                                <input type="hidden" id="tag_list" name="tag" value="@tagArray"/>
                                                <ul class="list_tag">
                                                    @foreach (var tag in tagList) {
                                                        <li>@tag.Title<span class="del"></span></li>
                                                    }
                                                    <li class="add">
                                                        <span class="tagwrap">
                                                            <input id="new_tag" class="text w_8 ac_input valid" type="text" autocomplete="off">
                                                        </span>
                                                        <a id="add_tag" class="btn_2 ml_1 btn">添 加</a>
                                                    </li>
                                                </ul>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Relation) {
                                                <span>实现中</span>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Comment) {
                                                <a href="/m/comment?nodeId=@Model.Id" target="_blank">@(item.FieldName)管理</a>
                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Quiz) {
                                                <a href="/m/quiz/listQuiz?nodeId=@Model.Id&type=@item.DefaultValue" target="_blank">
                                                    题库管理</a>
                                            } else {
                                                <textarea validate="@item.Validator" name="field.@item.FieldName" id="@item.FieldName" >@fieldValue</textarea>
                                                <script type="text/javascript">
                                                    UE.getEditor('@item.FieldName')
                                                </script>
                                                <div class="exp ml_1">@item.Hint</div>@*
                                                if (((Dictionary<long, string>)ViewBag.KeywordDict).ContainsKey(item.Id)) {
                                                <br />
                                                <input type="button" value="点击提取关键字" onclick=' getContentTxt("@item.FieldName    ", @item.Id) ' />
                                                <br />
                                                <span style="float: left;">关键字：</span>
                                                <input type="text" name="keyword.@item.Id" id="keyword_@item.FieldName" value="@ViewBag.KeywordDict[item.Id]"  />
                                                }*@
                                            }
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
            }
            @if (isSeo) {
                <div class="table_form form_main">
                    <div class="scrolltab-item-t">
                        <span class="btn"></span>SEO设置
                    </div>
                    <div class="pl_2">
                        <table>
                            <tbody>
                                <tr>
                                    <th width="80">页面标题：</th>
                                    <td>
                                        <input type="text" class="text w_37" name="seo.Title" value="@ViewBag.NodeSeo.Title"/>
                                        <input type="hidden" value="@ViewBag.NodeSeo.Id" name="seo.Id"/>
                                    </td>
                                </tr>
                                <tr>
                                    <th width="60">页面关键字：</th>
                                    <td>
                                        <input type="text" class="text w_37" name="seo.Keyword" value="@ViewBag.NodeSeo.Keyword"/>
                                    </td>
                                </tr>
                                <tr>
                                    <th width="60">页面描述：</th>
                                    <td>
                                        <textarea name="seo.Description" class="w_58 h_10">@ViewBag.NodeSeo.Description</textarea>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            }
        </div>
        <div class="submitbox p_2 extra_normal">
            <input type="submit" class="btn_1" value="提    交" />
            <ul style="display: none" id="tag_source">
                @foreach (var tag in @ViewBag.TagList) {
                    <li>@tag.Title</li>
                }
            </ul>
        </div>
    </form>
</div>
<script>
    function ajaxLoadList() {
        $.ajax({
            url: "/m/menu/MenuNodeDetatil/@ViewBag.Menu.Id",
            beforeSend: function () {
                $('.loading').show();
            },
            success: function (data) {
                $('.js_ajaxLoad').html(data);
                $('.loading').hide();
            }
        });
    }

    $(function () {
        $("#pbody > .extra").addClass("scrolltab");
        $(".scrolltab").each(function () {
            var $this = $(this);
            $this.scrollTab({
                offset: 180,
                beforeActive: function ($item) {
                    var $tabContainer = $this.find(".scrolltab-triggers");
                    if ($this.hasClass("scrolltab-2") ? ($this.scrollTop() <= 60) : ($this.scrollTop() <= 100)) {
                        $tabContainer.css({ "position": "relative", top: 0, width: $tabContainer.parent().width() });
                    } else {
                        $tabContainer.css({ "position": "fixed", top: 61, width: $tabContainer.parent().width() });
                    }
                }
            });
        });
    });
</script>
<script type="text/javascript" src="/Themes/CoralAdmin/_misc/scripts/ajaxLoad.js"></script>
